package com.shxzz.easy12306.services.pay.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author shxzz
 * @create 2024-03-12-20:49
 */
@RequiredArgsConstructor
@Configuration
@EnableConfigurationProperties(AliPayProperties.class)
public class AliPayConfiguration {

    private final AliPayProperties aliPayProperties;

    @Bean
    public AlipayClient alipayClient() throws AlipayApiException {
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl(aliPayProperties.getServerUrl());
        alipayConfig.setAppId(aliPayProperties.getAppId());
        alipayConfig.setPrivateKey(aliPayProperties.getPrivateKey());
        alipayConfig.setAlipayPublicKey(aliPayProperties.getAlipayPublicKey());
        return new DefaultAlipayClient(alipayConfig);
    }
}
